package util;


import java.io.IOException;
import java.util.List;

import pojo.Area;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


public class JsonUtil {
	public static String areaToJson(Area a) throws JsonProcessingException{
		String jsonStr;
		ObjectMapper mapper = new ObjectMapper();
		jsonStr = mapper.writeValueAsString(a)+"\n";
		return jsonStr;
	}
	public static String areasToJson(List<Area> al) throws JsonProcessingException{
		String jsonStr;
		ObjectMapper mapper = new ObjectMapper();
		jsonStr = mapper.writeValueAsString(al)+"\n";
		return jsonStr;
	}
	

	public static Area jasonlToProtocol(String jsonStr) throws IOException{
		Area area;
		ObjectMapper mapper = new ObjectMapper();
		System.out.println("jsonStr = "+ jsonStr);
		area = mapper.readValue(jsonStr, Area.class);
		return area;
	}
}
